<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/vue.js"></script>
    <script src="js/axios.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.zhimg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.zhimg.com/element-ui/lib/index.js"></script>
</head>
<body>
<div id="app">
    <el-row>
    <el-col :lg="24" >
        <el-card class="box-card" >
            <div>
                <el-button type="primary"  style="margin-bottom: 10px; border-radius: 0px;">返回</el-button>
                <el-button type="primary"  style="margin-bottom: 10px; border-radius: 0px;" @click="dialogVisible = true">添加试题</el-button>
            </div>
        </el-card>
    </el-col>
    </el-row>
    <el-row>
        <el-card class="box-card" >
            <!-- 上部条件选项框 start-->
            <el-row>
                <el-col :lg="8">
                    <el-form :inline="true" :model="formForSearch" class="demo-form-inline">
                        <el-form-item label="标签">
                            <el-input v-model="formForSearch.labelName" placeholder="请输入标签"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="search" style="border-radius: 0px;">查询</el-button>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>

            <el-row style="top: 10px">
                <el-col :lg="18">
                    <!-- 上部条件选项框 end-->
                    <template>
                        <el-table :data="tableData" border style="width: 100%">
                            <el-table-column
                                    prop="name"
                                    label="标签"
                                    width="400">
                            </el-table-column>
                            <el-table-column
                                    fixed="right"
                                    label="操作"
                                    width="400">
                                <template slot-scope="scope">
                                    <el-button @click="handleClick(scope.row)" type="text" size="small">编辑</el-button>
                                    <el-button type="text" size="small">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </template>
                </el-col>
            </el-row>
        </el-card>
    </el-row>
    <el-dialog title="添加标签" :visible.sync="dialogVisible" >
        <el-form :model="formForAdd" ref="formForAdd"  label-width="80px">
            <el-form-item label="标签" prop="name">
                <el-input v-model="formForAdd.name"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button @click="resetForm('formForAdd')">重置</el-button>
                <el-button type="primary" @click="dialogVisible = false,AddSubmit()">确 定</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</div>
<script>
    new Vue({
        el:"#app",
        data:{
            formForSearch:{
                labelName:""
            },
            tableData:[],
            dialogVisible:false,
            formForAdd:{
                name:""
            }
        },
        mounted(){
            this.storage=window.localStorage;
            this.token=this.storage.getItem("token");
            this.refreshToken=this.storage.getItem("refreshToken");
            axios.get("/label/all",{
                headers:{
                    'Content-Type':'application/json;charset=UTF-8',
                    "token":this.token,
                    "refreshToken":this.refreshToken
                }
            }).then(res=>{
                    this.tableData=res.data;
            })
        },
        methods: {
            search() {
                let param = new URLSearchParams();
                param.append("name", this.formForSearch.labelName);
                axios.post("label/search", param).then(res => {
                    this.tableData = res.data;
                })
            },
            AddSubmit(){
                console.log(this.formForAdd.name);
                this.$confirm("是否确定提交","提示",{
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'info'
                }).then(()=>{
                    if(this.formForAdd.name.trim()!=""){
                        let param = new URLSearchParams();
                        param.append("name",this.formForAdd.name);
                        this.$message({
                            type: 'success',
                            message: '添加成功!'
                        });
                    }else {
                        this.$message({
                            type: 'info',
                            message: '不能输入空值'
                        });
                    }
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
                this.$nextTick()
            },
            handleClick(row) {
                console.log(row);
            },
        }
    })
</script>
</body>
</html>